﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Cofe.Core.Property
{
    public static class IPropertyDictionaryExtension
    {
        public static List<string> GetPropertiesStringWithDefaultValue(this IPropertyDictionary propDic)
        {
            return (from prop in propDic.GetPropertiesWithDefaultValue()
                    select propDic.GetPropertyString(prop)).ToList();
        }

        public static bool HasProperty(this IPropertyDictionary propDic, string propertyString)
        {
            object property = propDic.GetProperty(propertyString);
            if (property != null)
                return propDic.HasProperty(property);
            else throw new KeyNotFoundException(propertyString);
        }
       
        public static PropertyPair GetDefaultValuePP(this IPropertyDictionary propDic, object property)
        {
            if (propDic.AttributeHelper.HasDefaultValue(property))
            {
                object defValue = propDic.AttributeHelper.GetDefaultValue(property);
                return PropertyPair.FromValue(property, defValue);
            }
            throw new NotSupportedException();
        }

        public static PropertyPair GetDefaultValuePP(this IPropertyDictionary propDic, string propertyString)
        {
            object property = propDic.GetProperty(propertyString);
            return propDic.GetDefaultValuePP(property);
        }
    }
}
